package com.cdsxt.util;


/**
 * 
 */
public class ThrowableUtil {

	public static void main(String[] args) {

		
		
		try {
			int a=1/0;
		} catch (Exception e) {
			System.out.println(e.toString());
			System.out.println("===");
			System.err.println(throwableToString(e));
		}
		
		
	}

	/**
	 * 把异常对象==》转换为==》字符串
	 */
	public static String throwableToString(Throwable t) {
		StringBuilder sb = new StringBuilder();
		sb.append("【异常的类】：" + t.getClass().getName() + "\n");
		sb.append("【异常的消息】：" + t.getMessage() + "\n");
		sb.append("【异常的堆栈信息】：\n");
		StackTraceElement[] stArr = t.getStackTrace();
		for (StackTraceElement st : stArr) {
			sb.append(st.toString() + "\n");
		}
		return sb.toString();
	}
}
